#include "StdAfx.h"
#include "Obj.h"
#include "Matrix.h"

long CObj::m_lFileVersion=0;

CObj::CObj(void)
{
}

CObj::CObj(const CObj *pObj)
{
}

CObj::~CObj(void)
{
}

bool CObj::IsEntityObj() const
{
	return false;
}

bool CObj::IsDisplayObj() const
{
	return false;
}

bool CObj::IsLayer() const
{
	return false;
}

//bool CObj::IsPin() const
//{
//	return false;
//}

bool CObj::IsNoteObj() const
{
	return false;
}

void CObj::Serialize(CArchive & ar)
{
}

CObj * CObj::Clone() const
{
	return NULL;
}

void CObj::Transform(const CMatrix transf)
{

}

bool CObj::GetBox(double & dblLeft, double & dblBottom, double & dblRight, double & dblTop) const
{
	return false;
}

void CObj::Clear()
{

}

//void CObj::DisplayProps(CPropertiesWnd *pPropsWnd)
//{
//
//}
//
//void CObj::PropChanged(const CMFCPropertyGridProperty * pProp)
//{
//
//}

bool CObj::WriteString(CArchive & ar, const CString & strText)
{
#ifdef _UNICODE
	unsigned int nBytes=WideCharToMultiByte(CP_UTF8, 0, strText, strText.GetLength(), NULL, 0, NULL, NULL);
	char * str=new char[nBytes+1];
	WideCharToMultiByte(CP_UTF8, 0, strText, strText.GetLength(), str, nBytes, NULL, NULL);
	ar<<nBytes;
	ar.Write((void *)str, nBytes);
	delete []str;

	return true;
#else
	unsigned int nBytes = strText.GetLength();
	CString szNoConst = CString(strText);
	char* cStr = szNoConst.GetBuffer(0);
	ar << nBytes;
	ar.Write((void*)cStr, nBytes);
	return true;
#endif // _UNICODE
}

bool CObj::ReadString(CArchive & ar, CString & strText)
{
#ifdef _UNICODE
	unsigned int uSize;
	ar>>uSize;
	char *str=new char[uSize+1];
	ar.Read((void *)str, uSize);
	str[uSize]='\0';

	unsigned int uWCharSize=MultiByteToWideChar(CP_UTF8, 0, str, uSize, NULL, 0);
	wchar_t *wstr=new wchar_t[uWCharSize+1];
	MultiByteToWideChar(CP_UTF8, 0, str, uSize, wstr, uWCharSize);
	wstr[uWCharSize]=L'\0';

	strText=wstr;
	delete []str;
	delete []wstr;

	return true;
#else
	unsigned int uSize;
	ar>>uSize;
	char *str=new char[uSize+1];
	ar.Read((void *)str, uSize);
	str[uSize]='\0';
	
	strText = CString(str);

	return true;
#endif // _UNICODE
}